export default class AudioUtils{
    private static _Instance:AudioUtils;

    private currentMusicId:number=-1;

    private currentMusicName:string="";
    public static getInstance(){
        if(!this._Instance){
            this._Instance = new AudioUtils()
        }
        return this._Instance
    }

    public playBgMusic(music){
        let self = this;
        console.log("playMusic~~~~~~~~~~~~~~~",this.currentMusicId,this.currentMusicName)
        if(this.currentMusicName == music){
            return
        }
        this.currentMusicName=music;
        if(this.currentMusicId!=-1){
            this.stopBgMusic();
        }
        cc.loader.load(cc.url.raw("resources/audio/"+music),function(err,musicRaw){
            self.currentMusicId = cc.audioEngine.play(musicRaw,true,1)
        });
    }
    public stopBgMusic(){
        console.log("stopMusic~~~~~~~~~~~~~~~",this.currentMusicId)
        cc.audioEngine.stop(this.currentMusicId);
    }
    public playEffect(music){
        let self=this;
        cc.loader.load(cc.url.raw("resources/audio/"+music),function(err,musicRaw){
            cc.audioEngine.play(musicRaw,false,1)
        });
    }
}